package com.brainhealth.web.controller.customer;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.brainhealth.common.annotation.Anonymous;
import com.sun.jna.platform.win32.WinDef;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.brainhealth.common.annotation.Log;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.common.enums.BusinessType;
import com.brainhealth.customer.domain.CustomerScore;
import com.brainhealth.customer.service.ICustomerScoreService;
import com.brainhealth.common.utils.poi.ExcelUtil;
import com.brainhealth.common.core.page.TableDataInfo;

/**
 * 会员质量评分Controller
 * 
 * @author wolong
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/customer/customerScore")
public class CustomerScoreController extends BaseController
{
    @Autowired
    private ICustomerScoreService customerScoreService;

    /**
     * 查询会员质量评分列表
     */
    @PreAuthorize("@ss.hasPermi('customer:customerScore:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerScore customerScore)
    {
        startPage();
        List<CustomerScore> list = customerScoreService.selectCustomerScoreList(customerScore);
        return getDataTable(list);
    }

    /**
     * 导出会员质量评分列表
     */
    @PreAuthorize("@ss.hasPermi('customer:customerScore:export')")
    @Log(title = "会员质量评分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerScore customerScore)
    {
        List<CustomerScore> list = customerScoreService.selectCustomerScoreList(customerScore);
        ExcelUtil<CustomerScore> util = new ExcelUtil<CustomerScore>(CustomerScore.class);
        util.exportExcel(response, list, "会员质量评分数据");
    }

    /**
     * 获取会员质量评分详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:customerScore:query')")
    @GetMapping(value = "/{customerScoreId}")
    public AjaxResult getInfo(@PathVariable("customerScoreId") Long customerScoreId)
    {
        return success(customerScoreService.selectCustomerScoreByCustomerScoreId(customerScoreId));
    }

    /**
     * 新增会员质量评分
     */
    @PreAuthorize("@ss.hasPermi('customer:customerScore:add')")
    @Log(title = "会员质量评分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerScore customerScore)
    {
        return toAjax(customerScoreService.insertCustomerScore(customerScore));
    }

    /**
     * 修改会员质量评分
     */
    @PreAuthorize("@ss.hasPermi('customer:customerScore:edit')")
    @Log(title = "会员质量评分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerScore customerScore)
    {
        return toAjax(customerScoreService.updateCustomerScore(customerScore));
    }

    /**
     * 删除会员质量评分
     */
    @PreAuthorize("@ss.hasPermi('customer:customerScore:remove')")
    @Log(title = "会员质量评分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerScoreIds}")
    public AjaxResult remove(@PathVariable Long[] customerScoreIds)
    {
        return toAjax(customerScoreService.deleteCustomerScoreByCustomerScoreIds(customerScoreIds));
    }

    /**
     * 添加会员学习库观看质量评分
     */
    @Anonymous
    @PostMapping("/addCustomerScore")
    public AjaxResult setCustomerScore(HttpServletRequest request, @RequestBody Map<String, Object> map)
    {
        Long learnId = Long.valueOf(map.get("learnId").toString());
        boolean result = customerScoreService.setCustomerScore(request, learnId);
        if (result)
        {
            return AjaxResult.success("添加质量评分成功！");
        }
        return AjaxResult.error("学习质量评分已添加！");
    }
}
